package com.mpgame.database.mysql.mapper.game;

import com.mpgame.database.mysql.mapper.BaseMapper;
import com.mpgame.database.mysql.model.game.MonsterStore;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.util.List;

@Mapper
public interface MonsterStoreMapper extends BaseMapper<MonsterStore> {
    
    @Insert("INSERT INTO monster_store (monster_id, player_id, lv, wisdom, melee_atk, magic_atk, melee_def, magic_def, speed, health, skill1_id, skill2_id, skill3_id, skill4_id) VALUES (#{monsterId}, #{playerId}, #{lv}, #{wisdom}, #{meleeAtk}, #{magicAtk}, #{meleeDef}, #{magicDef}, #{speed}, #{health}, #{skill1Id}, #{skill2Id}, #{skill3Id}, #{skill4Id})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(MonsterStore monsterStore);

    @Select("SELECT * FROM monster_store WHERE id = #{id}")
    MonsterStore selectById(@Param("id") int id);

    @Select("SELECT * FROM monster_store WHERE player_id = #{playerId}")
    List<MonsterStore> selectByPlayerId(@Param("playerId") int playerId);

    @Select("SELECT * FROM monster_store WHERE monster_id = #{monsterId}")
    List<MonsterStore> selectByMonsterId(@Param("monsterId") int monsterId);

    @Select("SELECT * FROM monster_store WHERE player_id = #{playerId} AND monster_id = #{monsterId}")
    List<MonsterStore> selectByPlayerAndMonster(@Param("playerId") int playerId, @Param("monsterId") int monsterId);

    @Select("SELECT * FROM monster_store")
    List<MonsterStore> selectAll();

    @Update("UPDATE monster_store SET lv = #{lv}, wisdom = #{wisdom}, melee_atk = #{meleeAtk}, magic_atk = #{magicAtk}, melee_def = #{meleeDef}, magic_def = #{magicDef}, speed = #{speed}, health = #{health}, skill1_id = #{skill1Id}, skill2_id = #{skill2Id}, skill3_id = #{skill3Id}, skill4_id = #{skill4Id} WHERE id = #{id}")
    int updateById(MonsterStore monsterStore);
}
